/**
 * 
 */
package xiaojian.toolkit.bean.xip.test;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import xiaojian.toolkit.bean.bytebean.core.BeanFieldCodec;
import xiaojian.toolkit.util.ByteUtils;

/**
 * @author hp
 *
 */
public class XipDemo {

	public static void main(String[] args) {
		AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(
				"xiaojian/toolkit/bean/xip/test/xipDemo2.xml");

		BeanFieldCodec xipBeanCodec = (BeanFieldCodec) ctx.getBean("beanCodec");

		SampleSsip ssip = new SampleSsip();

		ssip.setName("hello, world!");

		byte[] bytesBody = xipBeanCodec.encode(xipBeanCodec
				.getEncContextFactory().createEncContext(ssip, ssip.getClass(),
						null));

		System.out.println(ByteUtils.bytesAsHexString(bytesBody, 1024));

		System.out.println(xipBeanCodec.decode(xipBeanCodec
				.getDecContextFactory().createDecContext(bytesBody,
						SampleSsip.class, null, null)).getValue());

		// DefaultEndpointFactory sender =
		// (DefaultEndpointFactory)ctx.getBean("endpointFactory");
		//
		// while (true) {
		// sender.send(ssip);
		// try {
		// Thread.sleep(1000);
		// } catch (InterruptedException e) {
		// e.printStackTrace();
		// }
		// }
	}
}
